package cn.itcast.dao;

import cn.itcast.domain.Student;
import cn.itcast.domain.Teacher;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TeacherDao {

    // 查询所有账户
    @Select("select * from teacher")
    public List<Teacher> findAll();

    // 根据用户名和密码查询用户
    @Select("select * from teacher where tno = #{username} and password = #{password}")
    public Teacher findByStuAndPas(@Param("username") String username,
                                   @Param("password") String password);

    // 分页查询
//    SELECT * FROM student WHERE student.`classno`
//    IN (SELECT tc.`classno` FROM tc,teacher
//            WHERE teacher.`tno` = "1234" AND teacher.`tno` = tc.`tno` )
//    ORDER BY sno
//    LIMIT 1,10;

    @Select("SELECT * FROM student WHERE student.`classno` " +
            "IN (SELECT tc.`classno` FROM tc,teacher WHERE teacher.`tno` = #{username} " +
            "AND teacher.`tno` = tc.`tno` ) "  )
    public List<Student> findByAll(@Param("username") String username);

}
